import 'package:flutter/material.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/models/book/BookFilters.dart';
import 'package:get/get.dart';

class BookFilterDropwown extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    final BooksController _booksController = Get.find();
    _booksController.getBooksFilters();
    var data = _booksController.bookfilters;
    return Obx(() {
      return ListView.builder(
        itemBuilder: (BuildContext context, int index) => DataPopUp(data[index]),
        itemCount: data.length,
      );
    });
  }
}

class DataPopUp extends StatelessWidget {
  const DataPopUp(this.popup);
  final BookFilter popup;

  Widget _buildTiles(BookFilter root) {
    if (root.children != null && root.children!.isEmpty)
      return ListTile(title: Text(root.label.toString()));
    return ExpansionTile(
      key: PageStorageKey<BookFilter>(root),
      title: Text(
        root.label.toString(),
      ),
      children:
           root.children!.map(_buildTiles).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return _buildTiles(popup);
  }
}
